import { Body, Controller, Delete, Get, HttpStatus, Param, Post, Put, Query, Res } from '@nestjs/common';
import { CreatePermissionDto } from './dto/create-permission.dto';
import { UpdatePermissionDto } from './dto/update-permission.dto';
import { PermissionService } from './permission.service';

@Controller('permission')
export class PermissionController {

  constructor(private permissionService: PermissionService) {
  }

  @Post()
  async create(@Res() res, @Body() body: CreatePermissionDto) {
    await this.permissionService.create(body);
    return res.status(HttpStatus.CREATED).send({ status: 'success' });
  }

  @Delete(':id')
  async delete(@Param() id: number) {
    await this.permissionService.delete(id);
    return { status: 'success' };
  }

  @Put(':id')
  async update(@Param() id: number, updatePermissionDto: UpdatePermissionDto) {
    await this.permissionService.update(id, updatePermissionDto);
    return { status: 'success' };
  }

  @Get()
  findAll(@Query('key') key) {
    return this.permissionService.findAll(key);
  }
}
